home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / me_cd25.zip / MUTT2.ZIP / MODELINE.MUT < prev    next >
Text File  |  1992-11-09  |  4KB  |  146 lines

  1. ;; modeline.mut :  Modeline central.  Control what the mode line looks
  2. ;;   like and other mode related stuff.
  3.  
  4. ;; Modeline format:
  5. ;;   Change_flag Buffer-name (major-mode : minor-mode) File: File-name
  6. ;;     Change_flag : -- or **
  7. ;;     major_mode  : "", C, Mutt, Picture, etc
  8. ;;     minor_mode  : comment, etc
  9.  
  10. ;; Routines:
  11. ;;   (local-modeline-hook
  12. ;;     name-of-the-routine-to-call-instead-of-modeline-hook)
  13. ;;     If the buffer has a local modeline-hook, it is called instead of the
  14. ;;       global (modeline-hook).
  15. ;;   (major-mode name-of-major-mode) : (major-mode "foo") sets the major
  16. ;;     mode name to foo (displayed on the modeline) and (major-mode)
  17. ;;     returns the current major mode name.
  18. ;;   (minor-mode name-of-minor-mode)
  19. ;;   (clear-modes) : Remove all the local key bindings, mode names and
  20. ;;     reset the buffer local sysvars.
  21.  
  22. ;; Uses:
  23. ;;   Buffer variables:
  24. ;;     major-mode
  25. ;;     minor-mode
  26. ;;     local-modeline-hook
  27. ;; Needed:
  28. ;;   A way to stack modes so I can easily nest modes.
  29.  
  30. ;; C Durland 10/89    Public Domain
  31.  
  32. (include me2.h)
  33.  
  34. (string message)
  35.  
  36. (defun
  37.   local-modeline-hook (string hook-name)
  38.     { (buffer-var "local-modeline-hook" hook-name) }
  39.   major-mode (string name) { (mode-name "major-mode" (push-args 0)) }
  40.   minor-mode (string name) { (mode-name "minor-mode" (push-args 0)) }
  41.   clear-modes
  42.   {
  43.     (bind-local-key "clear-keymap")
  44.     (major-mode "")(minor-mode "")
  45.     (tab-stops 0)(word-wrap 0)
  46. ;;!! probably should have a buffer-var "clear-mode", that, if it exists, is
  47. ;;  the name of a routine that will get rid of all the mode stuff.
  48.   }
  49.  
  50.   modeline-message (string text)
  51.   {
  52.     (if (== (nargs) 1)        ;; got a text
  53.     {
  54.       (message text)
  55. ;;;!!! need to update all visible buffers
  56.       (buffer-flags -1 BFMode)        ;; force update of modeline
  57.     })
  58.     message    ;; return the message
  59.   }
  60. )
  61.  
  62. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  63. ;;;;;;;;;;;;; Modeline Hook ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  64. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  65.  
  66.    ;; Global rouine to format a modeline for a buffer.
  67.    ;; If the buffer has its own modeline hook, that is called instead.
  68.    ;; Returns:  A string to be used as the modeline.
  69. (defun
  70.   modeline-hook
  71.   {
  72.     (if (!= "" (buffer-var "local-modeline-hook"))
  73.     {
  74.       (floc (buffer-var "local-modeline-hook")())
  75.       (done)
  76.     })
  77.     (concat
  78. message
  79.       (if (!= 0 (bit-and BFNoCare (buffer-flags -1)))
  80.     "  "
  81.     (if (buffer-modified -1) "**" "--"))
  82.       " ME2 "
  83.       (if (!= 0 (overstrike)) "[jam] " "")
  84.       "-- " (buffer-name -1) " "
  85.       (modes)            ;; "(modes)" or "--"
  86.       (if (!= "" (file-name -1))
  87.         (concat " File:" (sub~ (file-name -1)) " ")
  88.     "")
  89.       "-"            ;; repeat this to the end of the modeline
  90.     )
  91.   }
  92.   modes        HIDDEN        ;; spit out the major and minor mode names
  93.   {
  94.     (concat
  95.       (if (!= "" (buffer-var "major-mode"))
  96.     {
  97.       (concat
  98.         "("
  99.         (buffer-var "major-mode")
  100.         (if (!= "" (buffer-var "minor-mode"))
  101.           (concat " : " (buffer-var "minor-mode"))
  102.           "")
  103.         ")" )
  104.     }
  105.     "--"))
  106.   }
  107. )
  108.  
  109. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  110. ;;;;;;;;;;;; Gory details ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  111. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  112.  
  113. (defun
  114.   init-mline-bvars
  115.   {
  116.     (create-buffer-var STRING "local-modeline-hook" "major-mode" "minor-mode")
  117.   }
  118.   !1 MAIN HIDDEN    ;; do this WAY early, before mode-line-hook is called
  119.   {
  120.     (init-mline-bvars)        ;; make sure *scratch* is updated
  121.     (register-hook BUFFER-CREATED-HOOK "init-mline-bvars")
  122.   }
  123.   mode-name (string mode-var mode-name) HIDDEN
  124.   {
  125.     (if (== (nargs) 2)        ;; got mode-name
  126.     {
  127.       (buffer-var mode-var mode-name)
  128.       (buffer-flags -1 BFMode)        ;; force update of modeline
  129.     })
  130.     (buffer-var mode-var)    ;; return the mode name
  131.   }
  132. )
  133.  
  134. (defun
  135.   sub~ (string dir-name) HIDDEN    ; convert /users/craig/... to ~/...
  136.   {
  137.     (int n)
  138.  
  139.     (n (length-of (getenv "HOME")))
  140.     (if (and (!= n 0) (== (getenv "HOME") (extract-elements dir-name 0 n)))
  141.     (concat "~" (extract-elements dir-name n 1000))
  142.     dir-name
  143.     )
  144.   }
  145. )
  146.